package com.ccrfid.rmc6.service.device;

import com.ccrfid.rmc6.appconfig.exception.pojo.AppException;
import com.ccrfid.rmc6.entity.device.LocatorEntity;
import com.ccrfid.rmc6.repository.search.SearchCriteria;
import com.ccrfid.rmc6.resource.device.pojo.FloorPos;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import java.util.List;

public interface LocatorService {
    //
    Page<LocatorEntity> getLocatorInfoPage(SearchCriteria criteria, Pageable pageable);
    List<LocatorEntity> getLocatorList(SearchCriteria criteria, Sort sort);
    List<LocatorEntity> getAllLocators();

    //
    LocatorEntity getLocator(Long locatorId);

    //
    @Cacheable(value = "locators", key = "#locatorAddress")
    LocatorEntity getLocatorByLocatorAddress(Integer locatorAddress);

    //
    @CachePut(value = "locators", key = "#result.locatorAddress")
    LocatorEntity createLocator(LocatorEntity entity) throws AppException;

    //
    @CachePut(value = "locators", key = "#result.locatorAddress")
    LocatorEntity updateLocator(Long locatorId, LocatorEntity entity) throws AppException;

    void updateOnlineStatus(Integer locatorAddress, Integer onlineStatus);

    //
    @CachePut(value = "locators", key = "#result.locatorAddress")
    LocatorEntity updatePosition(Long locatorId, FloorPos floorPos) throws AppException;

    //
    @CachePut(value = "locators", key = "#result.locatorAddress")
    LocatorEntity deletePosition(Long locatorId) throws AppException;

    //
    @CacheEvict(value = "locators", allEntries = true)
    int deleteLocatorsInfo(List<Long> idList);
}
